home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / os2 / xdsn217.zip / SAMPLES / FINDPROC / findproc.mod next >
Text File  |  1996-07-10  |  2KB  |  103 lines

  1. (* Copyright (c) 1996 xTech Ltd, Russia. All Rights Reserved. *)
  2.  
  3. (* Sample tool for XDS IDE: Finding procedure headings        *)
  4.  
  5. <*+ M2EXTENSIONS *>
  6.  
  7. MODULE FindProc;
  8.  
  9. IMPORT SYSTEM;
  10. IMPORT ProgramArgs, TextIO, STextIO, IOChan, RndFile, IOResult;
  11. IMPORT Strings;
  12.  
  13. IMPORT IDE := xShell;
  14.  
  15.  
  16. VAR
  17.   ide  : BOOLEAN;
  18.   name : ARRAY [0..255] OF CHAR;
  19.   file : RndFile.ChanId;
  20.   size : RndFile.FilePos;
  21.   line : CARDINAL;
  22.  
  23. PROCEDURE FatalError(s: ARRAY OF CHAR);
  24. BEGIN
  25.   IF ide THEN
  26.     IDE.String(s);
  27.   ELSE
  28.     STextIO.WriteString(s);
  29.     STextIO.WriteLn;
  30.   END;
  31.   HALT;
  32. END FatalError;
  33.  
  34. PROCEDURE OpenFile;
  35. VAR
  36.   res  : RndFile.OpenResults;
  37. BEGIN
  38.   IF NOT ProgramArgs.IsArgPresent() THEN
  39.     FatalError("Too few arguments");
  40.   END;
  41.   TextIO.ReadToken(ProgramArgs.ArgChan(),name);
  42.   RndFile.OpenOld(file,name,RndFile.text,res);
  43.   IF res <> RndFile.opened THEN
  44.     FatalError("Failed to open a file");
  45.   END;
  46. END OpenFile;
  47.  
  48. PROCEDURE ReadFile;
  49. VAR
  50.   buf   : ARRAY [0..255] OF CHAR;
  51.   found : BOOLEAN;
  52.   pos   : CARDINAL;
  53. BEGIN
  54.   line := 0;
  55.   size := RndFile.EndPos(file);
  56.   IF ide THEN
  57.     IDE.Comment(name);
  58.     IDE.StartJob("Scanning",size);
  59.   END;
  60.   LOOP
  61.     TextIO.ReadString(file,buf);
  62.     CASE IOResult.ReadResult(file) OF
  63.     |IOResult.allRight:
  64.       Strings.FindNext('PROCEDURE', buf, 0, found, pos);
  65.       IF found THEN
  66.         IF ide THEN
  67.           IDE.Error(IDE.MSG_WARNING,pos,line,name,buf);
  68.           IDE.String(buf);
  69.           IDE.String(15C+12C);
  70.         END;
  71.       END;
  72.     |IOResult.endOfLine:
  73.       TextIO.SkipLine(file); INC(line);
  74.     |IOResult.endOfInput:
  75.       EXIT
  76.     END;
  77.     IF ide THEN
  78.       IDE.Progress(line,-VAL(INTEGER,RndFile.CurrentPos(file)));
  79.     END;
  80.   END;
  81. END ReadFile;
  82.  
  83. PROCEDURE CloseFile;
  84. BEGIN
  85.   RndFile.Close(file);
  86. END CloseFile;
  87.  
  88. BEGIN
  89.   ide := IDE.Start();
  90.   IF ide THEN
  91.     IDE.TurnSortingOff;
  92.     IDE.Caption("Finding procedures...");
  93.   END;
  94.   OpenFile;
  95.   ReadFile;
  96.   CloseFile;
  97.   IF ide THEN
  98.     IDE.Caption("Done");
  99.   END;
  100. FINALLY
  101.   IF ide THEN IDE.Finish; END;
  102. END FindProc.
  103.